/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller.report;

import com.thienloc.omap.entity.Recvsms;
import com.thienloc.omap.session.RecvsmsFacade;
import com.thienloc.omap.util.JsfUtil;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@RequestScoped
public class RecvSmsBean {
    
    @EJB
    private RecvsmsFacade facade;
    private List<Recvsms> list;
    
    @PostConstruct
    public void init() {
        try {
            list = facade.findAll();
            Comparator<Recvsms> comparator = new Comparator<Recvsms>() {
                
                @Override
                public int compare(Recvsms o1, Recvsms o2) {
                    return o2.getRecvTime().compareTo(o1.getRecvTime());
                }
            };
            Collections.sort(list, comparator);
        } catch (Exception ex) {
            LoggerFactory.getLogger(RecvSmsBean.class).error("", ex);
            JsfUtil.addErrorMessage("Lỗi", "Không lấy được thông tin MO từ DB");
        }
    }
    
    public List<Recvsms> getList() {
        return list;
    }
}
